#ifndef _hpsfrom_zero_log_h
#define _hpsfrom_zero_log_h

#include <iostream>
#include <string>
#include <memory>
#include <list>

namespace hpsfrom_zero {

//日志级别
class LogLevel{
public:
    enum Level{
        DEBUG = 1,
        INFO = 2,
        WARN = 3,
        ERROR = 4,
        FATAL = 5
    };
};

//日志事件
class LogEvent{
public:
    typedef std::shared_ptr<LogEvent> ptr;
    LogEvent();
    ~LogEvent();

    std::string getMessage() const;
private:
    const char* m_file = nullptr; //文件名
    int32_t m_line = 0; //行号
    int32_t m_elapse = 0; //程序启动到现在的毫秒数
    int32_t m_threadId = 0; //线程ID
    int32_t m_fiberId = 0; //协程ID
    int64_t m_time = 0; //时间戳

    std::string m_message; //日志内容
};

//日志器
class logger{
public:
    typedef std::shared_ptr<logger> ptr;
    
    logger(const std::string& name = "root");
    ~logger();

    void log(LogLevel::Level level, LogEvent::ptr event);
    void debug(LogEvent::ptr event);
    void info(LogEvent::ptr event);
    void warn(LogEvent::ptr event);
    void error(LogEvent::ptr event);
    void fatal(LogLevel::Level level, LogEvent::ptr event);

    void addAppender(std::shared_ptr<LogAppender> appender);
    void delAppender(std::shared_ptr<LogAppender> appender);

    //添加和删除日志级别
    LogLevel::Level getLevel() const { return m_level; }
    void setLevel(LogLevel::Level level) { m_level = level; }

private:
    std::string m_name; //日志名称
    LogLevel::Level m_level; //日志级别
    std::shared_ptr<LoggerFormatter> m_formatter; //日志格式器
    std::shared_ptr<LogAppender> m_appender; //日志输出器
    std::list<LogAppender::ptr> m_appenders;
};

//日志输出器
class LogAppender{
public:
    typedef std::shared_ptr<LogAppender> ptr;
    LogAppender();
    virtual ~LogAppender();
    void log(LogLevel::Level level, LogEvent::ptr event);
    
private:
    std::string m_name; //日志名称
    LogLevel::Level m_level; //日志级别
    std::shared_ptr<LoggerFormatter> m_formatter; //日志格式器
};

//日志格式化器
class LoggerFormatter{
public:
    typedef std::shared_ptr<LoggerFormatter> ptr;

    std::string format(LogEvent::ptr event);
    LoggerFormatter();
    ~LoggerFormatter();

    std::string format(const std::string& msg);
private:

};

//输出到控制台的Appender
class StdLogAppender : public LogAppender {
public:


};

//输出到文件的Appender
class FileLogAppender : public LogAppender {

};

};

#endif